/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JpanelOferiment2.java
 *
 * Created on 19-may-2010, 17:57:33
 */

package edu.ieslaferreria.creditsintesis.builders.Swing;

import edu.ieslaferreria.creditsintesis.rmi.Client;
import edu.ieslaferreria.creditsintesis.rmi.GameEventInteracctionTwoPanels;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;

/**
 *
 * @author Administrador
 */
public class JpanelOferiment2 extends JPanelGame {
  
    /** Creates new form JpanelOferiment2 */
    public JpanelOferiment2() {
        initComponents();
        jTextArea1.setEditable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        buttonGroup5 = new javax.swing.ButtonGroup();
        jRadioButtonOk = new javax.swing.JRadioButton();
        jRadioButtonNoOk = new javax.swing.JRadioButton();
        jPanelChat = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jTextField1 = new javax.swing.JTextField();
        jButtonChat = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        jRadioButtonOk.setText("Aceptar");
        jRadioButtonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonOkActionPerformed(evt);
            }
        });

        jRadioButtonNoOk.setText("Rechazar");
        jRadioButtonNoOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonNoOkActionPerformed(evt);
            }
        });

        jPanelChat.setBorder(javax.swing.BorderFactory.createTitledBorder("Chat"));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanelChatLayout = new javax.swing.GroupLayout(jPanelChat);
        jPanelChat.setLayout(jPanelChatLayout);
        jPanelChatLayout.setHorizontalGroup(
            jPanelChatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelChatLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE))
        );
        jPanelChatLayout.setVerticalGroup(
            jPanelChatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelChatLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonChat.setText("Comunicar");
        jButtonChat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonChatActionPerformed(evt);
            }
        });

        jTextField2.setText("No ha elegido nada aun");

        jLabel1.setText("Opcion elegida por el otro Player");

        jLabel2.setText("Pulsa si quieres o no aceptar la Opcion del otro player");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelChat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE))))
                .addGap(20, 20, 20))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jRadioButtonOk)
                        .addGap(76, 76, 76)
                        .addComponent(jRadioButtonNoOk))
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 169, Short.MAX_VALUE)
                .addComponent(jButtonChat)
                .addGap(30, 30, 30))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelChat, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonChat, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButtonNoOk)
                            .addComponent(jRadioButtonOk))))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonOkActionPerformed
        // TODO add your handling code here:
        
          HashMap<String,List<String>>res= new HashMap();

       String resString = OK;
       ArrayList<String> resArray =  new ArrayList();


       resArray.add(resString);
       res.put(RESPOSTA_PROPOSICIO,resArray);


        try {
            this.getPontPanel().send(new GameEventInteracctionTwoPanels(-1, resArray, res, this.getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JpanelOferiment2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jRadioButtonOkActionPerformed

    private void jButtonChatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChatActionPerformed
      HashMap<String,List<String>>res= new HashMap();

       String resString = getClient().getNom() + ": " + jTextField1.getText();
       ArrayList<String> resArray =  new ArrayList();


       resArray.add(resString);
       res.put(CHAT,resArray);


        try {
            this.getPontPanel().send(new GameEventInteracctionTwoPanels(-1,resArray, res, this.getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JpanelOferiment.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButtonChatActionPerformed

    private void jRadioButtonNoOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonNoOkActionPerformed

    // TODO add your handling code here:

          HashMap<String,List<String>>res= new HashMap();

       String resString = NO;
       ArrayList<String> resArray =  new ArrayList();


       resArray.add(resString);
       res.put(RESPOSTA_PROPOSICIO,resArray);


        try {
            this.getPontPanel().send(new GameEventInteracctionTwoPanels(-1, resArray, res, this.getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JpanelOferiment2.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_jRadioButtonNoOkActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.ButtonGroup buttonGroup5;
    private javax.swing.JButton jButtonChat;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanelChat;
    private javax.swing.JRadioButton jRadioButtonNoOk;
    private javax.swing.JRadioButton jRadioButtonOk;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

    public void update(Map<String, List<String>> opcions,ArrayList<String> extras) {
      
        if(opcions.get(CHAT)!=null){
        jTextArea1.setText(jTextArea1.getText() + opcions.get(CHAT).toString() + "\n");

        }else if(opcions.get(OPCIO_BASICA)!=null){
        jTextField2.setText(opcions.get(OPCIO_BASICA).toString());

        }
    }

   
}